
import Vue from 'vue'
import Vuex from 'vuex'
import { setItem, getItem } from '@/utils/storage'
Vue.use(Vuex)
const TOKEN_KEY = 'TOUTIAO_USER'
export default new Vuex.Store({
  state: {
    // 给他初始值，读取本地的token
    user: getItem(TOKEN_KEY)
  },
  mutations: {
    setUser (state, data) {
      // 把传回来的值赋给user，实现实时更新
      state.user = data
      // 调用本地存储的方法，把token存储到本地
      setItem(TOKEN_KEY, state.user)
    }
  },
  actions: {
  },
  modules: {
  }
})
